
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 05/30/2013 10:18:30
-- Generated from EDMX file: E:\CafeOnline\CafeOnline.Domain\Entities\CafeOnlineModel.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [TnT];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_AreaDetails_Areas]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[AreaDetails] DROP CONSTRAINT [FK_AreaDetails_Areas];
GO
IF OBJECT_ID(N'[dbo].[FK_AreaDetails_TimeRanges]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[AreaDetails] DROP CONSTRAINT [FK_AreaDetails_TimeRanges];
GO
IF OBJECT_ID(N'[dbo].[FK_BookDetails_Books]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BookDetails] DROP CONSTRAINT [FK_BookDetails_Books];
GO
IF OBJECT_ID(N'[dbo].[FK_Books_Customers]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Books] DROP CONSTRAINT [FK_Books_Customers];
GO
IF OBJECT_ID(N'[dbo].[FK_Books_Employees]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Books] DROP CONSTRAINT [FK_Books_Employees];
GO
IF OBJECT_ID(N'[dbo].[FK_Books_Tables]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Books] DROP CONSTRAINT [FK_Books_Tables];
GO
IF OBJECT_ID(N'[dbo].[FK_Customers_CustomerTypes]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Customers] DROP CONSTRAINT [FK_Customers_CustomerTypes];
GO
IF OBJECT_ID(N'[dbo].[FK_GroupDetails_Employees]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[GroupDetails] DROP CONSTRAINT [FK_GroupDetails_Employees];
GO
IF OBJECT_ID(N'[dbo].[FK_GroupDetails_Groups]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[GroupDetails] DROP CONSTRAINT [FK_GroupDetails_Groups];
GO
IF OBJECT_ID(N'[dbo].[FK_Groups_Roles]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Groups] DROP CONSTRAINT [FK_Groups_Roles];
GO
IF OBJECT_ID(N'[dbo].[FK_OrderDetailProductDetail]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[OrderDetails] DROP CONSTRAINT [FK_OrderDetailProductDetail];
GO
IF OBJECT_ID(N'[dbo].[FK_OrderDetails_Orders]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[OrderDetails] DROP CONSTRAINT [FK_OrderDetails_Orders];
GO
IF OBJECT_ID(N'[dbo].[FK_Orders_Customers]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Orders] DROP CONSTRAINT [FK_Orders_Customers];
GO
IF OBJECT_ID(N'[dbo].[FK_Orders_Employees]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Orders] DROP CONSTRAINT [FK_Orders_Employees];
GO
IF OBJECT_ID(N'[dbo].[FK_ProductBookDetail]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BookDetails] DROP CONSTRAINT [FK_ProductBookDetail];
GO
IF OBJECT_ID(N'[dbo].[FK_ProductProductDetail]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ProductDetails] DROP CONSTRAINT [FK_ProductProductDetail];
GO
IF OBJECT_ID(N'[dbo].[FK_Products_ProductGroups]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Products] DROP CONSTRAINT [FK_Products_ProductGroups];
GO
IF OBJECT_ID(N'[dbo].[FK_Tables_Areas]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Tables] DROP CONSTRAINT [FK_Tables_Areas];
GO
IF OBJECT_ID(N'[dbo].[FK_UnitProductDetail]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ProductDetails] DROP CONSTRAINT [FK_UnitProductDetail];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[AreaDetails]', 'U') IS NOT NULL
    DROP TABLE [dbo].[AreaDetails];
GO
IF OBJECT_ID(N'[dbo].[Areas]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Areas];
GO
IF OBJECT_ID(N'[dbo].[BookDetails]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BookDetails];
GO
IF OBJECT_ID(N'[dbo].[Books]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Books];
GO
IF OBJECT_ID(N'[dbo].[Customers]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Customers];
GO
IF OBJECT_ID(N'[dbo].[CustomerTypes]', 'U') IS NOT NULL
    DROP TABLE [dbo].[CustomerTypes];
GO
IF OBJECT_ID(N'[dbo].[Employees]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Employees];
GO
IF OBJECT_ID(N'[dbo].[GroupDetails]', 'U') IS NOT NULL
    DROP TABLE [dbo].[GroupDetails];
GO
IF OBJECT_ID(N'[dbo].[Groups]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Groups];
GO
IF OBJECT_ID(N'[dbo].[OrderDetails]', 'U') IS NOT NULL
    DROP TABLE [dbo].[OrderDetails];
GO
IF OBJECT_ID(N'[dbo].[Orders]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Orders];
GO
IF OBJECT_ID(N'[dbo].[ProductDetails]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ProductDetails];
GO
IF OBJECT_ID(N'[dbo].[ProductGroups]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ProductGroups];
GO
IF OBJECT_ID(N'[dbo].[Products]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Products];
GO
IF OBJECT_ID(N'[dbo].[Roles]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Roles];
GO
IF OBJECT_ID(N'[dbo].[Tables]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Tables];
GO
IF OBJECT_ID(N'[dbo].[TimeRanges]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TimeRanges];
GO
IF OBJECT_ID(N'[dbo].[Units]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Units];
GO
IF OBJECT_ID(N'[dbo].[Versions]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Versions];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'AreaDetails'
CREATE TABLE [dbo].[AreaDetails] (
    [FK_AreaId] int  NOT NULL,
    [FK_TimeRangeId] int  NOT NULL,
    [Cost] float  NOT NULL
);
GO

-- Creating table 'Areas'
CREATE TABLE [dbo].[Areas] (
    [AreaId] int IDENTITY(1,1) NOT NULL,
    [AreaName] nvarchar(150)  NOT NULL
);
GO

-- Creating table 'BookDetails'
CREATE TABLE [dbo].[BookDetails] (
    [BookDetailId] bigint  NOT NULL,
    [FK_BookId] bigint  NOT NULL,
    [FK_ItemId] int  NOT NULL,
    [Quantity] int  NOT NULL,
    [Description] nvarchar(150)  NULL,
    [ProductProductId] int  NOT NULL
);
GO

-- Creating table 'Books'
CREATE TABLE [dbo].[Books] (
    [BookId] bigint IDENTITY(1,1) NOT NULL,
    [FK_TableId] int  NULL,
    [StartTime] datetime  NOT NULL,
    [EndDate] datetime  NULL,
    [FK_CustomerId] int  NULL,
    [CustomerName] nvarchar(100)  NULL,
    [Phone] nvarchar(12)  NOT NULL,
    [Identity] nchar(10)  NULL,
    [Address] nvarchar(150)  NULL,
    [BookStatus] int  NOT NULL,
    [Deposit] float  NOT NULL,
    [SeatCount] int  NULL,
    [Description] nvarchar(250)  NULL,
    [FK_EmployeeId] int  NULL
);
GO

-- Creating table 'Customers'
CREATE TABLE [dbo].[Customers] (
    [CustomerId] int  NOT NULL,
    [CustomerName] nvarchar(150)  NOT NULL,
    [FK_CustomerTypeId] int  NULL,
    [Address] nvarchar(150)  NOT NULL,
    [Phone] nvarchar(12)  NULL,
    [CustomerCode] nchar(10)  NULL
);
GO

-- Creating table 'CustomerTypes'
CREATE TABLE [dbo].[CustomerTypes] (
    [CustomerTypeId] int IDENTITY(1,1) NOT NULL,
    [CustomerTypeName] nvarchar(50)  NOT NULL,
    [Discount] float  NOT NULL
);
GO

-- Creating table 'Employees'
CREATE TABLE [dbo].[Employees] (
    [username] nvarchar(50)  NOT NULL,
    [password] nvarchar(150)  NULL,
    [FullName] nvarchar(150)  NULL,
    [Phone] nvarchar(12)  NULL,
    [Address] nvarchar(150)  NULL,
    [EmployeeId] int IDENTITY(1,1) NOT NULL
);
GO

-- Creating table 'GroupDetails'
CREATE TABLE [dbo].[GroupDetails] (
    [GroupDetailId] int IDENTITY(1,1) NOT NULL,
    [FK_GroupId] int  NOT NULL,
    [FK_EmployeeId] int  NOT NULL
);
GO

-- Creating table 'Groups'
CREATE TABLE [dbo].[Groups] (
    [GroupId] int IDENTITY(1,1) NOT NULL,
    [GroupName] nvarchar(150)  NOT NULL,
    [FK_RoleId] int  NOT NULL,
    [ModuleName] nvarchar(50)  NULL,
    [CanAdd] bit  NOT NULL,
    [CanEdit] bit  NOT NULL,
    [CanDelete] bit  NOT NULL
);
GO

-- Creating table 'OrderDetails'
CREATE TABLE [dbo].[OrderDetails] (
    [OrderDetailId] bigint IDENTITY(1,1) NOT NULL,
    [FK_OrderId] bigint  NOT NULL,
    [FK_ItemId] int  NOT NULL,
    [Quantity] int  NOT NULL,
    [Discount] float  NULL,
    [ProductDetail_Id] int  NOT NULL
);
GO

-- Creating table 'Orders'
CREATE TABLE [dbo].[Orders] (
    [OrderId] bigint IDENTITY(1,1) NOT NULL,
    [FK_EmployeeId] int  NOT NULL,
    [FK_CustomerId] int  NULL,
    [FullName] nvarchar(150)  NULL,
    [OrderDate] datetime  NOT NULL,
    [StartTime] time  NULL,
    [EndTime] time  NULL,
    [Description] nvarchar(250)  NULL,
    [Discount] float  NULL,
    [TotalCost] float  NULL
);
GO

-- Creating table 'Roles'
CREATE TABLE [dbo].[Roles] (
    [RoleId] int IDENTITY(1,1) NOT NULL,
    [RoleName] nvarchar(150)  NULL
);
GO

-- Creating table 'Tables'
CREATE TABLE [dbo].[Tables] (
    [TableId] int  NOT NULL,
    [TableName] nvarchar(150)  NOT NULL,
    [FK_AreaId] int  NOT NULL,
    [SeatCount] int  NOT NULL,
    [Avaible] bit  NOT NULL,
    [Description] nvarchar(250)  NULL
);
GO

-- Creating table 'TimeRanges'
CREATE TABLE [dbo].[TimeRanges] (
    [TimeRangeId] int IDENTITY(1,1) NOT NULL,
    [StartDate] time  NOT NULL,
    [EndDate] time  NOT NULL,
    [Description] nvarchar(150)  NULL
);
GO

-- Creating table 'Units'
CREATE TABLE [dbo].[Units] (
    [UnitId] int IDENTITY(1,1) NOT NULL,
    [UnitName] nvarchar(150)  NOT NULL
);
GO

-- Creating table 'Versions'
CREATE TABLE [dbo].[Versions] (
    [VersionId] char(5)  NOT NULL,
    [Description] nvarchar(150)  NULL,
    [Date] datetime  NOT NULL
);
GO

-- Creating table 'Products'
CREATE TABLE [dbo].[Products] (
    [ProductId] int IDENTITY(1,1) NOT NULL,
    [ProductNo] nchar(20)  NOT NULL,
    [ProductName] nvarchar(250)  NULL,
    [ProductDesc] nvarchar(250)  NULL,
    [FK_ProductGroupId] int  NULL,
    [FK_SupplierId] int  NULL,
    [IsActive] bit  NOT NULL,
    [IsDelete] bit  NOT NULL,
    [CreateDate] datetime  NOT NULL,
    [UpdateDate] datetime  NOT NULL,
    [UserCreate] nvarchar(50)  NULL,
    [UserUpdate] nvarchar(50)  NULL,
    [ProductImage] nvarchar(250)  NULL,
    [ProductSupplierPrice] float  NULL,
    [ProductSalePrice] float  NULL,
    [FK_StockID] int  NULL
);
GO

-- Creating table 'ProductGroups'
CREATE TABLE [dbo].[ProductGroups] (
    [ProductGroupId] int IDENTITY(1,1) NOT NULL,
    [ProductGroupParentId] int  NULL,
    [ProductGroupName] nvarchar(250)  NOT NULL,
    [ProductGroupDesc] nvarchar(250)  NULL,
    [ImageUrl] nvarchar(250)  NULL,
    [IsActive] bit  NOT NULL,
    [IsDelete] bit  NOT NULL,
    [CreateDate] datetime  NOT NULL,
    [UpdateDate] datetime  NOT NULL,
    [UserCreate] nvarchar(50)  NULL,
    [UserUpdate] nvarchar(50)  NULL
);
GO

-- Creating table 'ProductDetails'
CREATE TABLE [dbo].[ProductDetails] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Description] nvarchar(max)  NOT NULL,
    [Price] nvarchar(max)  NOT NULL,
    [ProductProductId] int  NOT NULL,
    [UnitUnitId] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [FK_AreaId], [FK_TimeRangeId] in table 'AreaDetails'
ALTER TABLE [dbo].[AreaDetails]
ADD CONSTRAINT [PK_AreaDetails]
    PRIMARY KEY CLUSTERED ([FK_AreaId], [FK_TimeRangeId] ASC);
GO

-- Creating primary key on [AreaId] in table 'Areas'
ALTER TABLE [dbo].[Areas]
ADD CONSTRAINT [PK_Areas]
    PRIMARY KEY CLUSTERED ([AreaId] ASC);
GO

-- Creating primary key on [BookDetailId] in table 'BookDetails'
ALTER TABLE [dbo].[BookDetails]
ADD CONSTRAINT [PK_BookDetails]
    PRIMARY KEY CLUSTERED ([BookDetailId] ASC);
GO

-- Creating primary key on [BookId] in table 'Books'
ALTER TABLE [dbo].[Books]
ADD CONSTRAINT [PK_Books]
    PRIMARY KEY CLUSTERED ([BookId] ASC);
GO

-- Creating primary key on [CustomerId] in table 'Customers'
ALTER TABLE [dbo].[Customers]
ADD CONSTRAINT [PK_Customers]
    PRIMARY KEY CLUSTERED ([CustomerId] ASC);
GO

-- Creating primary key on [CustomerTypeId] in table 'CustomerTypes'
ALTER TABLE [dbo].[CustomerTypes]
ADD CONSTRAINT [PK_CustomerTypes]
    PRIMARY KEY CLUSTERED ([CustomerTypeId] ASC);
GO

-- Creating primary key on [EmployeeId] in table 'Employees'
ALTER TABLE [dbo].[Employees]
ADD CONSTRAINT [PK_Employees]
    PRIMARY KEY CLUSTERED ([EmployeeId] ASC);
GO

-- Creating primary key on [GroupDetailId] in table 'GroupDetails'
ALTER TABLE [dbo].[GroupDetails]
ADD CONSTRAINT [PK_GroupDetails]
    PRIMARY KEY CLUSTERED ([GroupDetailId] ASC);
GO

-- Creating primary key on [GroupId] in table 'Groups'
ALTER TABLE [dbo].[Groups]
ADD CONSTRAINT [PK_Groups]
    PRIMARY KEY CLUSTERED ([GroupId] ASC);
GO

-- Creating primary key on [OrderDetailId] in table 'OrderDetails'
ALTER TABLE [dbo].[OrderDetails]
ADD CONSTRAINT [PK_OrderDetails]
    PRIMARY KEY CLUSTERED ([OrderDetailId] ASC);
GO

-- Creating primary key on [OrderId] in table 'Orders'
ALTER TABLE [dbo].[Orders]
ADD CONSTRAINT [PK_Orders]
    PRIMARY KEY CLUSTERED ([OrderId] ASC);
GO

-- Creating primary key on [RoleId] in table 'Roles'
ALTER TABLE [dbo].[Roles]
ADD CONSTRAINT [PK_Roles]
    PRIMARY KEY CLUSTERED ([RoleId] ASC);
GO

-- Creating primary key on [TableId] in table 'Tables'
ALTER TABLE [dbo].[Tables]
ADD CONSTRAINT [PK_Tables]
    PRIMARY KEY CLUSTERED ([TableId] ASC);
GO

-- Creating primary key on [TimeRangeId] in table 'TimeRanges'
ALTER TABLE [dbo].[TimeRanges]
ADD CONSTRAINT [PK_TimeRanges]
    PRIMARY KEY CLUSTERED ([TimeRangeId] ASC);
GO

-- Creating primary key on [UnitId] in table 'Units'
ALTER TABLE [dbo].[Units]
ADD CONSTRAINT [PK_Units]
    PRIMARY KEY CLUSTERED ([UnitId] ASC);
GO

-- Creating primary key on [VersionId] in table 'Versions'
ALTER TABLE [dbo].[Versions]
ADD CONSTRAINT [PK_Versions]
    PRIMARY KEY CLUSTERED ([VersionId] ASC);
GO

-- Creating primary key on [ProductId] in table 'Products'
ALTER TABLE [dbo].[Products]
ADD CONSTRAINT [PK_Products]
    PRIMARY KEY CLUSTERED ([ProductId] ASC);
GO

-- Creating primary key on [ProductGroupId] in table 'ProductGroups'
ALTER TABLE [dbo].[ProductGroups]
ADD CONSTRAINT [PK_ProductGroups]
    PRIMARY KEY CLUSTERED ([ProductGroupId] ASC);
GO

-- Creating primary key on [Id] in table 'ProductDetails'
ALTER TABLE [dbo].[ProductDetails]
ADD CONSTRAINT [PK_ProductDetails]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [FK_AreaId] in table 'AreaDetails'
ALTER TABLE [dbo].[AreaDetails]
ADD CONSTRAINT [FK_AreaDetails_Areas]
    FOREIGN KEY ([FK_AreaId])
    REFERENCES [dbo].[Areas]
        ([AreaId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [FK_TimeRangeId] in table 'AreaDetails'
ALTER TABLE [dbo].[AreaDetails]
ADD CONSTRAINT [FK_AreaDetails_TimeRanges]
    FOREIGN KEY ([FK_TimeRangeId])
    REFERENCES [dbo].[TimeRanges]
        ([TimeRangeId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AreaDetails_TimeRanges'
CREATE INDEX [IX_FK_AreaDetails_TimeRanges]
ON [dbo].[AreaDetails]
    ([FK_TimeRangeId]);
GO

-- Creating foreign key on [FK_AreaId] in table 'Tables'
ALTER TABLE [dbo].[Tables]
ADD CONSTRAINT [FK_Tables_Areas]
    FOREIGN KEY ([FK_AreaId])
    REFERENCES [dbo].[Areas]
        ([AreaId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Tables_Areas'
CREATE INDEX [IX_FK_Tables_Areas]
ON [dbo].[Tables]
    ([FK_AreaId]);
GO

-- Creating foreign key on [FK_BookId] in table 'BookDetails'
ALTER TABLE [dbo].[BookDetails]
ADD CONSTRAINT [FK_BookDetails_Books]
    FOREIGN KEY ([FK_BookId])
    REFERENCES [dbo].[Books]
        ([BookId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_BookDetails_Books'
CREATE INDEX [IX_FK_BookDetails_Books]
ON [dbo].[BookDetails]
    ([FK_BookId]);
GO

-- Creating foreign key on [FK_CustomerId] in table 'Books'
ALTER TABLE [dbo].[Books]
ADD CONSTRAINT [FK_Books_Customers]
    FOREIGN KEY ([FK_CustomerId])
    REFERENCES [dbo].[Customers]
        ([CustomerId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Books_Customers'
CREATE INDEX [IX_FK_Books_Customers]
ON [dbo].[Books]
    ([FK_CustomerId]);
GO

-- Creating foreign key on [FK_EmployeeId] in table 'Books'
ALTER TABLE [dbo].[Books]
ADD CONSTRAINT [FK_Books_Employees]
    FOREIGN KEY ([FK_EmployeeId])
    REFERENCES [dbo].[Employees]
        ([EmployeeId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Books_Employees'
CREATE INDEX [IX_FK_Books_Employees]
ON [dbo].[Books]
    ([FK_EmployeeId]);
GO

-- Creating foreign key on [FK_TableId] in table 'Books'
ALTER TABLE [dbo].[Books]
ADD CONSTRAINT [FK_Books_Tables]
    FOREIGN KEY ([FK_TableId])
    REFERENCES [dbo].[Tables]
        ([TableId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Books_Tables'
CREATE INDEX [IX_FK_Books_Tables]
ON [dbo].[Books]
    ([FK_TableId]);
GO

-- Creating foreign key on [FK_CustomerTypeId] in table 'Customers'
ALTER TABLE [dbo].[Customers]
ADD CONSTRAINT [FK_Customers_CustomerTypes]
    FOREIGN KEY ([FK_CustomerTypeId])
    REFERENCES [dbo].[CustomerTypes]
        ([CustomerTypeId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Customers_CustomerTypes'
CREATE INDEX [IX_FK_Customers_CustomerTypes]
ON [dbo].[Customers]
    ([FK_CustomerTypeId]);
GO

-- Creating foreign key on [FK_CustomerId] in table 'Orders'
ALTER TABLE [dbo].[Orders]
ADD CONSTRAINT [FK_Orders_Customers]
    FOREIGN KEY ([FK_CustomerId])
    REFERENCES [dbo].[Customers]
        ([CustomerId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Orders_Customers'
CREATE INDEX [IX_FK_Orders_Customers]
ON [dbo].[Orders]
    ([FK_CustomerId]);
GO

-- Creating foreign key on [FK_EmployeeId] in table 'GroupDetails'
ALTER TABLE [dbo].[GroupDetails]
ADD CONSTRAINT [FK_GroupDetails_Employees]
    FOREIGN KEY ([FK_EmployeeId])
    REFERENCES [dbo].[Employees]
        ([EmployeeId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_GroupDetails_Employees'
CREATE INDEX [IX_FK_GroupDetails_Employees]
ON [dbo].[GroupDetails]
    ([FK_EmployeeId]);
GO

-- Creating foreign key on [FK_EmployeeId] in table 'Orders'
ALTER TABLE [dbo].[Orders]
ADD CONSTRAINT [FK_Orders_Employees]
    FOREIGN KEY ([FK_EmployeeId])
    REFERENCES [dbo].[Employees]
        ([EmployeeId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Orders_Employees'
CREATE INDEX [IX_FK_Orders_Employees]
ON [dbo].[Orders]
    ([FK_EmployeeId]);
GO

-- Creating foreign key on [FK_GroupId] in table 'GroupDetails'
ALTER TABLE [dbo].[GroupDetails]
ADD CONSTRAINT [FK_GroupDetails_Groups]
    FOREIGN KEY ([FK_GroupId])
    REFERENCES [dbo].[Groups]
        ([GroupId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_GroupDetails_Groups'
CREATE INDEX [IX_FK_GroupDetails_Groups]
ON [dbo].[GroupDetails]
    ([FK_GroupId]);
GO

-- Creating foreign key on [FK_RoleId] in table 'Groups'
ALTER TABLE [dbo].[Groups]
ADD CONSTRAINT [FK_Groups_Roles]
    FOREIGN KEY ([FK_RoleId])
    REFERENCES [dbo].[Roles]
        ([RoleId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Groups_Roles'
CREATE INDEX [IX_FK_Groups_Roles]
ON [dbo].[Groups]
    ([FK_RoleId]);
GO

-- Creating foreign key on [FK_OrderId] in table 'OrderDetails'
ALTER TABLE [dbo].[OrderDetails]
ADD CONSTRAINT [FK_OrderDetails_Orders]
    FOREIGN KEY ([FK_OrderId])
    REFERENCES [dbo].[Orders]
        ([OrderId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_OrderDetails_Orders'
CREATE INDEX [IX_FK_OrderDetails_Orders]
ON [dbo].[OrderDetails]
    ([FK_OrderId]);
GO

-- Creating foreign key on [FK_ProductGroupId] in table 'Products'
ALTER TABLE [dbo].[Products]
ADD CONSTRAINT [FK_Products_ProductGroups]
    FOREIGN KEY ([FK_ProductGroupId])
    REFERENCES [dbo].[ProductGroups]
        ([ProductGroupId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Products_ProductGroups'
CREATE INDEX [IX_FK_Products_ProductGroups]
ON [dbo].[Products]
    ([FK_ProductGroupId]);
GO

-- Creating foreign key on [ProductProductId] in table 'BookDetails'
ALTER TABLE [dbo].[BookDetails]
ADD CONSTRAINT [FK_ProductBookDetail]
    FOREIGN KEY ([ProductProductId])
    REFERENCES [dbo].[Products]
        ([ProductId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ProductBookDetail'
CREATE INDEX [IX_FK_ProductBookDetail]
ON [dbo].[BookDetails]
    ([ProductProductId]);
GO

-- Creating foreign key on [ProductProductId] in table 'ProductDetails'
ALTER TABLE [dbo].[ProductDetails]
ADD CONSTRAINT [FK_ProductProductDetail]
    FOREIGN KEY ([ProductProductId])
    REFERENCES [dbo].[Products]
        ([ProductId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ProductProductDetail'
CREATE INDEX [IX_FK_ProductProductDetail]
ON [dbo].[ProductDetails]
    ([ProductProductId]);
GO

-- Creating foreign key on [UnitUnitId] in table 'ProductDetails'
ALTER TABLE [dbo].[ProductDetails]
ADD CONSTRAINT [FK_UnitProductDetail]
    FOREIGN KEY ([UnitUnitId])
    REFERENCES [dbo].[Units]
        ([UnitId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UnitProductDetail'
CREATE INDEX [IX_FK_UnitProductDetail]
ON [dbo].[ProductDetails]
    ([UnitUnitId]);
GO

-- Creating foreign key on [ProductDetail_Id] in table 'OrderDetails'
ALTER TABLE [dbo].[OrderDetails]
ADD CONSTRAINT [FK_OrderDetailProductDetail]
    FOREIGN KEY ([ProductDetail_Id])
    REFERENCES [dbo].[ProductDetails]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_OrderDetailProductDetail'
CREATE INDEX [IX_FK_OrderDetailProductDetail]
ON [dbo].[OrderDetails]
    ([ProductDetail_Id]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------